package br.inatel.wiiproject.data;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

public class StoredData {
	
	private static final long serialVersionUID = 1L;
	private static ArrayList coordinates = null;
	private static StoredData storedData = null;
	
	private StoredData() {
		
	}
	
	private static ArrayList getCoordinates(){
		if (storedData == null){
			storedData = new StoredData();
			coordinates = new ArrayList();
		}
		return coordinates;
	}

	public static synchronized void addCoordinate(Coordinate coordinate){
		getCoordinates().add(coordinate);
	}
	
	public static synchronized void saveAll() {  
		try {
			ObjectOutputStream file = new ObjectOutputStream(new FileOutputStream("wiiproject_data.txt"));
			Data data = new Data();
			data.setCoordinates(StoredData.getCoordinates());
			file.writeObject(data); 
			file.close();  
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
	} 
	
}
